import { PromiseResponse } from '@/types/type'
import { LoginForm, AdminUserType } from './types'
import { request } from '@/utils/request'
import { MenuType } from '../menu/types'

/* eslint-disable no-unused-vars */
enum API {
    LOGIN_URL = '/auth/login',
    REFRESH_TOKEN_URL = '/auth/refreshToken',
    GET_ADMINUSER_INFO_URL = '/auth/getUserInfo',
    GET_AUTH_MENU_URL = '/Auth/GetAuthMenus',
    GET_AUTH_BUTTON_URL = '/Auth/GetAuthButtons',
    GET_AUTH_BUTTON_PERMISSIONS = '/Auth/GetAuthButtonPermissions',
}
/**
 * 登录
 * @param data 登录表单
 * @returns 用户信息
 */
export const adminlogin = (data: LoginForm): PromiseResponse<AdminUserType> => request(API.LOGIN_URL, 'POST', data)
/**
 * 刷新Token
 * @param refreshToken 刷新Token
 * @returns Token
 */
export const refreshToken = (refreshToken: string): PromiseResponse<string> => request(API.REFRESH_TOKEN_URL, 'POST', refreshToken)
/**
 * 获得登录用户信息
 * @returns 登录用户信息
 */
export const getAdminUserInfo = (): PromiseResponse<AdminUserType> => request(API.GET_ADMINUSER_INFO_URL)
/**
 * 根据用户Id获得权限菜单
 * @returns 权限菜单数组
 */
export const getAuthMenus = (id: number): PromiseResponse<MenuType[]> => request(API.GET_AUTH_MENU_URL, 'GET', {}, { id })
/**
 * 根据用户Id获得权限按钮
 * @returns 权限按钮数组
 */
export const getAuthButtons = (id: number): PromiseResponse<MenuType[]> => request(API.GET_AUTH_BUTTON_URL, 'GET', {}, { id })
/**
 * 根据用户Id获得按钮权限字段
 * @returns 按钮权限字段数组
 */
export const getAuthButtonPermissions = (id: number): PromiseResponse<string[]> => request(API.GET_AUTH_BUTTON_PERMISSIONS, 'GET', {}, { id })
